home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / KEYBOARD.SWG / 0037_Trapping ALT and CTRL.pas < prev    next >
Pascal/Delphi Source File  |  1993-08-27  |  2KB  |  87 lines

  1. {
  2. WILBERT VAN LEIJEN
  3.  
  4. > HEy, I have been using some routines to check if certain keys are pressed,
  5. > but I can't figure out how to test For ALT and CTRL key combinations.
  6. }
  7.  
  8. {$G+}
  9.  
  10. Uses
  11.   Dos, Crt;
  12.  
  13. Var
  14.   KeyHandlerProc : Procedure;
  15.   Int15Vector    : Pointer;
  16.  
  17. Const
  18.   AltStatus  : Array [Boolean] of String[5] = ('     ', ' ALT ');
  19.   CtrlStatus : Array [Boolean] of String[6] = ('      ', ' CTRL ');
  20.  
  21. Procedure KeyHandler; Far;
  22. Var
  23.   AltKey  : Boolean;
  24.   CtrlKey : Boolean;
  25.   WhereXY : Record
  26.     x, y : Byte;
  27.   end;
  28.  
  29. begin
  30.   AltKey  := False;
  31.   CtrlKey := False;
  32.  
  33.   Asm
  34.     MOV AH, 2
  35.     INT 16h
  36.     CMP AL, 8
  37.     JNE @1
  38.     INC [AltKey]
  39.    @1:
  40.     CMP AL, 4
  41.     JNE @2
  42.     INC [CtrlKey]
  43.    @2:
  44.   end;
  45.  
  46.   WhereXY.x := WhereX;
  47.   WhereXY.y := WhereY;
  48.   GotoXY(66, 25);
  49.   Write(AltStatus[AltKey], ' ', CtrlStatus[CtrlKey]);
  50.   GotoXY(WhereXY.x, WhereXY.y);
  51. end;  { KeyHandler }
  52.  
  53. { This INT 15h handler is called every time a key is pressed -
  54.   provided you're not running this Program on an XT-class machine }
  55.  
  56. Procedure TrapKeyboard; Assembler;
  57. Asm
  58.   PUSH   BX
  59.   PUSH   DS
  60.   PUSHF
  61.   MOV    BX, SEG @Data
  62.   MOV    DS, BX
  63.   CMP    AH, 4Fh
  64.   JNE    @ChainInt15
  65.   PUSH   ES
  66.   PUSHA
  67.   CALL   [KeyHandlerProc]
  68.   POPA
  69.   POP    ES
  70.  
  71.  @ChainInt15:
  72.   PUSHF
  73.   CALL   [Int15Vector]
  74.   POPF
  75.   POP    DS
  76.   POP    BX
  77.   IRET
  78. end;  { TrapKeyboard }
  79.  
  80. begin
  81.   GetIntVec($15, Int15Vector);
  82.   KeyHandlerProc := KeyHandler;
  83.   SetIntVec($15, @TrapKeyboard);
  84.   ReadLn;
  85.   SetIntVec($15, Int15Vector);
  86. end.
  87.